package com.niaobulashi.queue;

import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;

/**
 * 消息生产者
 *
 * @author yamikaze
 */
@Slf4j
public class Producer {

    public static final String MESSAGE_KEY = "message:queue";

    private RedisTemplate redisTemplate;

    private String producerName = "test_produce";

    private volatile int count;


    public void init(RedisTemplate redisTemplate) {
        this.redisTemplate = redisTemplate;
    }


    public void putMessage(String message) {
        Long size = redisTemplate.opsForList().leftPush(MESSAGE_KEY, message);
        log.info(producerName + ": 当前未被处理消息条数为:" + size);
        count++;
    }

    public int getCount() {
        return count;
    }


}